Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(preview): add experimental support for live document id sets #7398

Open
wants to merge 2 commits into
base: preview/add-observe-full-documents
Choose a base branch
from

Conversation

bjoerge
Copy link
Member

@bjoerge bjoerge commented Aug 20, 2024

Description

Note: builds upon the changes in #7397

This adds a new method unstable_observeDocumentIdSet(groqFilter, params) to the preview store that supports subscribing to a set of document ids that matches a provided groq filter. This method returns an observable that emits a new set of ids everytime a document is added or removed from the set of matching documents.

Under the hood it sets up a listener for the provided filter, upon receiving the welcome event it fetches the initial set of ids of matching documents, and thereafter it patches the set based on appear and disappear transition on the listener event.

Since all we have here are document ids, and we don't now the position newly added ids, ordering can only be done based on the id itself, so this API does not include a way to specify an order with the query/filter itself.

This PR also includes a hook useLiveDocumentSet(filter) (also internal for now), that maps every unique id in the set to a subscription for the complete document (using previewStore.observeDocument(id) implmeneted in #7397) . This hook is using rxjs-mergemap-array which makes sure that subscriptions to individual documents are made only once, even if the referential integrity of the set itself changes, and also makes sure to unsubscribe documents that disappear from the set.

What to review

Is the naming clear? I opted for "set" nomenclature to hint towards the "unordered" nature of the returned array (it is sorted by default, but consumers can also decide to add new items at the start or at the end).

Testing

These methods are only used in a feature branch for now, we'll look into some automated tests for them as we start relying on them more.

Notes for release

n/a – internal for now

@bjoerge bjoerge requested a review from a team as a code owner August 20, 2024 15:39
@bjoerge bjoerge requested review from ricokahler and removed request for a team August 20, 2024 15:39
Copy link

vercel bot commented Aug 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 20, 2024 3:39pm
performance-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 20, 2024 3:39pm
test-compiled-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 20, 2024 3:39pm
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 20, 2024 3:39pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 20, 2024 3:39pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Aug 20, 2024 3:39pm

Copy link
Contributor

No changes to documentation

Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] None 0 35.2 kB bjoerge

View full report↗︎

Copy link
Contributor

Component Testing Report Updated Aug 20, 2024 3:55 PM (UTC)

✅ All Tests Passed -- expand for details
File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 44s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 9s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 31s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 38s 11 7 0
formBuilder/inputs/PortableText/copyPaste/CopyPasteFields.spec.tsx ✅ Passed (Inspect) 0s 0 12 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 18s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 11s 3 0 0
formBuilder/inputs/PortableText/DragAndDrop.spec.tsx ✅ Passed (Inspect) 2m 33s 1 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 45s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 46s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 14s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 8s 3 9 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 26s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 18s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 1m 14s 21 0 0
formBuilder/tree-editing/TreeEditing.spec.tsx ✅ Passed (Inspect) 1m 50s 30 0 0
formBuilder/tree-editing/TreeEditingNestedObjects.spec.tsx ✅ Passed (Inspect) 19s 3 0 0

@bjoerge bjoerge force-pushed the preview/add-observe-full-documents branch 2 times, most recently from 5887a68 to 2897248 Compare August 27, 2024 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant